home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / i64.h < prev    next >
C/C++ Source or Header  |  2002-09-16  |  4KB  |  150 lines

  1. /* i64.h */
  2. /*--------------------------------------------------------------------------*\
  3.   Copyright (C) 1999 Douglas W. Sauder
  4.  
  5.   This software is provided "as is," without any express or implied
  6.   warranty.  In no event will the author be held liable for any damages
  7.   arising from the use of this software.
  8.  
  9.   Permission is granted to anyone to use this software for any purpose,
  10.   including commercial applications, and to alter it and redistribute it
  11.   freely, subject to the following restrictions:
  12.  
  13.   1. The origin of this software must not be misrepresented; you must not
  14.      claim that you wrote the original software. If you use this software
  15.      in a product, an acknowledgment in the product documentation would be
  16.      appreciated but is not required.
  17.   2. Altered source versions must be plainly marked as such, and must not be
  18.      misrepresented as being the original software.
  19.   3. This notice may not be removed or altered from any source distribution.
  20.  
  21.   The original distribution can be obtained from www.hunnysoft.com.
  22.   You can email the author at dwsauder@erols.com.
  23.  
  24.   $RCSfile: i64.h,v $
  25.   $Revision: 1.1.1.1 $
  26.   $Date: 2001/11/26 22:21:05 $
  27. \*--------------------------------------------------------------------------*/
  28.  
  29. #ifndef I64_MATH
  30. #define I64_MATH
  31.  
  32. typedef struct {
  33.     unsigned hi;  /* Most significant 32 bits */
  34.     unsigned lo;  /* Least significant 32 bits */
  35. } bigint;
  36.  
  37.  
  38. /* Compare n1 and n2.
  39.  *    Returns  1 if n1 > n2
  40.  *    Returns -1 if n1 < n2
  41.  *    Returns  0 if n1 = n2
  42.  */
  43. int i64_cmp(bigint n1, bigint n2);
  44.  
  45. #define I64_GREATER 1
  46. #define I64_LESS -1
  47. #define I64_EQUAL 0
  48.  
  49. /* Sign of n
  50.  *
  51.  *    Returns  1 if n > 0
  52.  *    Returns -1 if n < 0
  53.  *    Returns  0 if n = 0
  54.  */
  55. int i64_sgn(bigint n);
  56.  
  57. /* Left shift
  58.  *
  59.  *    Shift n to the left by b bits
  60.  *
  61.  *    Undefined if b < 0 or b > 63
  62.  */
  63. bigint i64_lshift(bigint n, int b);
  64.  
  65. /* Unsigned right shift
  66.  *
  67.  *    Shift n to the right by b bits.  Zeros are shifted in.
  68.  *
  69.  *    Undefined if b < 0 or b > 63
  70.  */
  71. bigint i64_urshift(bigint n, int b);
  72.  
  73. /* Signed right shift
  74.  *
  75.  *    Shift n to the right by b bits.  Zeros or ones are shifted in, depending
  76.  *    on the most leftmost bit in n.
  77.  *
  78.  *    Undefined if b < 0 or b > 63
  79.  */
  80. bigint i64_srshift(bigint n, int b);
  81.  
  82. /* Change sign of n
  83.  *
  84.  *    Returns -n
  85.  */
  86. bigint i64_inv(bigint n);
  87.  
  88. /* Add n1 and n2
  89.  *
  90.  *    Returns n1 + n2
  91.  */
  92. bigint i64_add(bigint n1, bigint n2);
  93.  
  94. /* Subtract n2 from n1
  95.  *
  96.  *    Returns n1 - n2
  97.  */
  98. bigint i64_sub(bigint n1, bigint n2);
  99.  
  100. /* Multiply n1 and n2
  101.  *
  102.  *    Returns n1 * n2
  103.  */
  104. bigint i64_mul(bigint multiplicand, bigint multiplier);
  105.  
  106. /* Divide dividend by divisor
  107.  *
  108.  *    Returns values quotient and remainder such that
  109.  *
  110.  *      dividend = (divisor * quotient) + remainder
  111.  */
  112. void i64_div(bigint dividend, bigint divisor, bigint *quotient, bigint *remainder);
  113.  
  114. /* Divide dividend by divisor (unsigned)
  115.  *
  116.  *    Returns values quotient and remainder such that
  117.  *
  118.  *      dividend = (divisor * quotient) + remainder
  119.  *
  120.  * Both dividend and divisor are treated as unsigned integers
  121.  */
  122. void i64_udiv(bigint dividend, bigint divisor, bigint *quotient, bigint *remainder);
  123.  
  124. /* Converts string to 64 bit integer
  125.  *
  126.  *    Returns 64 bit integer from ASCII representation in buffer str
  127.  *    Returns 0 on error
  128.  */
  129. bigint i64_atoi(const char *str);
  130.  
  131. /* Converts 64 bit integer to string
  132.  *
  133.  *     Fills buffer str with ASCII representation for n
  134.  */
  135. void i64_itoa(bigint n, char *str, int strSize);
  136.  
  137.  
  138. /* Following functions added by Paul Huxham 30/12/2000 */
  139.  
  140. /* Set the value of a bigint from a long */
  141. bigint i64_set( long n1 );
  142.  
  143. /* Set the value of a bigint from a ulong */
  144. bigint i64_uset( unsigned long n1 );
  145.  
  146. /* Multiply two ulongs together and return a bigint */
  147. bigint i64_uumul( unsigned long n1, unsigned long n2 );
  148.  
  149. #endif
  150.